import 'package:flutter/material.dart';
import 'package:ribo_base_core/base_models/base_chart_circular_diagram_model.dart';
import 'package:ribo_base_core/base_models/base_chart_model.dart';
import 'base_chart.dart';

class BaseChartCircularDiagram extends StatefulWidget {
  BaseChartCircularDiagram({Key key, @required this.model}) : super(key: key);
  final BaseChartCircularDiagramModel model;

  @override
  _BaseChartCircularDiagramState createState() =>
      _BaseChartCircularDiagramState();
}

class _BaseChartCircularDiagramState extends State<BaseChartCircularDiagram> {
  Map<String, dynamic> _option;

  @override
  Widget build(BuildContext context) {
    _handleModel();

    return BaseChart(
      model: BaseChartModel(
          style: widget.model?.style,
          option: this._option),
    );
  }

  void _handleModel(){
    this._option = {
      'tooltip': {
        'trigger': 'item',
        'formatter': widget.model?.tooltipFormatter?.toJson()
      },
      "series": [
        {
          'type': 'pie',
          'radius': ['40%', '70%'],
          'label': {
            "textStyle": {"color": '#800080'},
            "fontSize": 10,
            'formatter': widget.model?.labelFormatter?.toJson()
          },
          'labelLine': {'show': false},
          'data': widget.model?.data
        },
      ]
    };
  }
}
